Public Partial Class FrmListadoRemitos
    Inherits System.Web.UI.Page
    Private tblRemitos As CapaDeNegocios.nRemitoServicios = New CapaDeNegocios.nRemitoServicios
    Private TblClientes As CapaDeNegocios.nCliente = New CapaDeNegocios.nCliente
    Private tblDetalleRemito As CapaDeNegocios.nDetalleRemitoServicios = New CapaDeNegocios.nDetalleRemitoServicios
    Private tblordenservicio As CapaDeNegocios.nOrdenServicio = New CapaDeNegocios.nOrdenServicio
    Private tblSolicitudServicio As CapaDeNegocios.nSolicitudServicio = New CapaDeNegocios.nSolicitudServicio



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("Login") = "Anonimo" Then
            Response.Redirect("/")
        End If

        If Not Page.IsPostBack Then
            llenarCboClientes()
            lnkReporte.Visible = False
            llenarGvRemitos()
            lnkReporte.OnClientClick = "javascript:var popup = window.open('./Reportes/FrmRptRemitoServicio.aspx',(new Date().getTime()),'Width=900,Height=500,Scrollbars=NO,Resizable=NO,Location=NO,Menubar=NO,Status=NO,Titlebar=NO,Toolbar=NO')"
        End If

    End Sub
    Sub llenarCboClientes()
        CboClientes.DataSource = TblClientes.Listar("", "", "", "", "", "", "", "", "", "", "", "")
        CboClientes.DataValueField = "CodigoCliente"
        CboClientes.DataTextField = "RazonSocial"
        CboClientes.DataBind()

    End Sub
    Sub llenarGvRemitos()
        Dim Cliente As String
        Cliente = CboClientes.SelectedValue
        If Not (Cliente = "") Then
            GVRemito.DataSource = tblRemitos.BuscarFiltrado("", "", "", "", "", "", Cliente, "-1", "ACTIVO")
            GVRemito.DataBind()
            Me.lnkReporte.Visible = True
            Session("RptListadoRemitoServicio") = GVRemito.DataSource
        End If
    End Sub

    Protected Sub lnkCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkCancelar.Click
        llenarGvRemitos()
        llenarCboClientes()
    End Sub

    Protected Sub CboClientes_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboClientes.SelectedIndexChanged
        llenarGvRemitos()
    End Sub


    Protected Sub lnkVolver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkVolver.Click
        Response.Redirect("FrmRemitoServicio.aspx")
    End Sub

    Protected Sub GVRemito_RowCommand(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GVRemito.RowCommand
        Dim dtsCodigoDetalle As DataSet = New DataSet
        Dim CodigoDetalle As String
        Dim CodigoOrden As String
        Dim dtsCodigoOrden As DataSet = New DataSet

        If e.CommandName = "Select" Then
            HFRemito.Value = e.CommandSource.Parent.FindControl("HFCodigoRemito").value
            dtsCodigoDetalle = tblDetalleRemito.Buscar(0, 0, 0, HFRemito.Value, 0)
            For Each row As DataRow In dtsCodigoDetalle.Tables(0).Rows
                CodigoDetalle = row("codigoDetalleServicio")
                tblDetalleRemito.Eliminar(CodigoDetalle)
            Next
            tblRemitos.Eliminar(HFRemito.Value)
            dtsCodigoOrden = tblRemitos.BuscarFiltrado(HFRemito.Value, "", "", "", "", "", "", "", "")
            CodigoOrden = dtsCodigoOrden.Tables(0).Rows(0)("CodigoOrdenServicio")
            Convert.ToInt32(CodigoOrden)
            tblordenservicio.Modificar(CodigoOrden, New Date, "", "Emitida", 0)
        End If
        llenarGvRemitos()
    End Sub

    
End Class